<?php
get_header();
?>
	<section class="main">
		<nav class="main-nav">
			<ul>						
				<?php 
					$taxonomies = 'building-type';
					$args  = array('hide_empty'=>false);
					$terms = get_terms( $taxonomies, $args ) ;
					foreach($terms as $term){							
						if( $term->parent == 0 && get_tax_meta($term->term_id,'building_tax_show_home') == 1){
							?>
						<li <?php echo checkActiveMenuHome($term->term_id)?>><a href="<?php echo get_term_link($term,$taxonomies);?>"><?php echo $term->name;?></a></li>
						<li class="line-nav"></li>
					<?php
						}
					}
				?>
				<?php $pageid = 58 ;if(ICL_LANGUAGE_CODE == 'vi') $pageid = 76 ;?>
			   <li><a href="<?php echo get_page_link($pageid)?>">
					<?php echo get_page($pageid)->post_title; ?>
				</a></li>
			</ul>
		</nav>
    	<?php get_sidebar(); ?>        
        <!-- main content -->
        <section class="main-content">
        	
			<section class="discrumble">
				<?php
					$walker = '';
					if(get_search_query() == " "){
						$walker .= __('Search keyword : All ;','building');
					}else{
						$walker .= __('Search keyword : "','building') .get_search_query() .' ";';
					}if(isset($_GET['location']) and $_GET['location'] != ""){
						$walker .= __(' Location : ','building') . $_GET['location'];
					}if(isset($_GET['author']) and $_GET['author'] != ""){
						$walker .= __('; Author : ','building') . get_userdata($_GET['location'])->user_nicename;
					}
				?>
				<?php if(is_search()):?>
					<a class="home" href="<?php echo home_url();?>"><?php bloginfo('name')?></a>
					>>
					<?php echo $walker;?>					
				<?php else:?>
					<?php if(function_exists('bcn_display')){ bcn_display();}?>
				<?php endif;?>
			</section>			
			<section class="col-main">
				<?php do_action('toolbar_order');?>
				<ul class="item-list">
					<?php						
						global $wp_query;						
						$args_query = set_get_order();						
						$args = array_merge( $wp_query->query_vars, $args_query );		
						query_posts( $args );
						while ( have_posts() ) : the_post();
						
					?>
						<li class="item">
							<h4 class="item-image">
								<a href="<?php the_permalink();?>" title="<?php the_title();?>">									
									<?php returnImageFirst($post);?>
								</a>
							</h4>
							<div class="item-right">
								<h3 class="item-name">
									<a href="<?php the_permalink();?>" title="<?php the_title();?>"><?php the_title();?></a>
								</h3>	
								<p>
									<strong><?php _e('Type:','building')?></strong>
									<?php echo get_the_term_list( $post->ID, 'building-type', '', ', ', '' ); ?>
								</p>
								<p>									
									<strong><?php _e('Agent Name:','building')?></strong>
									<?php j_get_author();?>
								</p>
								<p>
									<strong><?php _e('Interior:','building')?></strong>
									<?php echo rwmb_meta('building_interior');?>
									
								</p>
								<p>
									<strong><?php _e('Price:','building')?></strong>
									<?php
										$currency = get_post_meta(get_the_ID() , 'building_currency' , true);
										$arr_currency = explode('/',$currency);
										$extra = '';
										$isForSale = get_post_meta(get_the_ID() ,'building_type', false);
										foreach( $isForSale as $items){
											if( $items == 'For Rent'){
												$extra = '/'.$arr_currency[1];
											}
										}
									?>
									<span class="price-list">$<?php echo number_format( get_post_meta(get_the_ID() , 'building_cost' , true), 2) ;?></span>									
								</p>
								<p>
									<strong><?php _e('Currency:','building')?></strong>
									<?php
										if(empty($extra)){
											echo $arr_currency[0];
										}else{
											echo $currency;
										}
									?>
								</p>		
								<p>
									<strong><?php _e('Company:','building')?></strong>
									<a href="?s=+&author=<?php echo $post->post_author;?>">
									<?php
										echo get_user_by( 'id' , $post->post_author ) -> company;
									?>
									</a>
								</p>
								<p>
									<strong><?php _e('Available:','building')?></strong>
									<?php echo rwmb_meta('building_available');?>																
								</p>
							</div>
						</li>
					<?php
						endwhile;
						wp_reset_postdata();
						if(function_exists('wp_pagenavi')){ wp_pagenavi(); }
					?>
				</ul>
			</section>
        </section>
        <!-- end main content -->
        <div class="clear"></div>
    </section>
    <!-- content -->
<?php get_footer(); ?>